package com.service.system.agent.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dao.AgentNewMapper;
import com.dao.HatAreaMapper;
import com.dao.HatCityMapper;
import com.dao.HatProvinceMapper;
import com.entity.AgentNewStatisticsVo;
import com.entity.system.AgentIncomeDetailNew;
import com.entity.system.AgentNew;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.system.agent.AgentNewService;
import com.util.Const;

@Service
public class AgentNewServiceImpl implements AgentNewService {

	@Autowired
	AgentNewMapper agentNewMapper;
	@Autowired
	HatProvinceMapper hatProvinceMapper;
	@Autowired
	HatCityMapper hatCityMapper;
	@Autowired
	HatAreaMapper hatAreaMapper;
	
	
	@Override
	public AgentNew selectByPrimaryKey(Long id) {
		return agentNewMapper.selectByPrimaryKey(id);
	}
	
	@Override
	public Map<String, Object> selectIncomeStatistics(Map<String, String> map) {
		 Map<String ,Object> map1 = new HashMap<>();
	        int pageNum = 1;
	        int pageSize = 10;
	        if(StringUtils.isNotEmpty(map.get("pageNum"))){
	           pageNum = Integer.parseInt(map.get("pageNum"));
	        }
	        if(StringUtils.isNotEmpty(map.get("pageSize"))){
	            pageSize = Integer.parseInt(map.get("pageSize"));
	        }
	        PageHelper.startPage(pageNum,pageSize);
	        List<AgentNewStatisticsVo> agentStatistics = agentNewMapper.selectIncomeStatistics(map);
	        PageInfo<AgentNewStatisticsVo> pageInfo = new PageInfo<>(agentStatistics);
	        map1.put("code", Const.SUCCESS_CODE);
	        map1.put("message","查询成功");
	        map1.put("agentStatistics",agentStatistics);
	        map1.put("page",pageInfo);
		return map1;
	}

	@Override
	public Map<String, Object> queryAgentIncomeList(Map<String, String> map) {
		 Map<String ,Object> map1 = new HashMap<>();
	        int pageNum = 1;
	        int pageSize = 10;
		if(StringUtils.isNotEmpty(map.get("pageNum"))){
	           pageNum = Integer.parseInt(map.get("pageNum"));
	        }
	        if(StringUtils.isNotEmpty(map.get("pageSize"))){
	            pageSize = Integer.parseInt(map.get("pageSize"));
	        }
	        PageHelper.startPage(pageNum,pageSize);
	        List<AgentNewStatisticsVo> agentIncomeList = agentNewMapper.queryAgentIncomeList(map);
	        for (AgentNewStatisticsVo agentNewStatisticsVo : agentIncomeList) {
	        	agentNewStatisticsVo.setProviceCode(hatProvinceMapper.findByProvinceId(agentNewStatisticsVo.getProviceCode()).getProvince());
	        	agentNewStatisticsVo.setCityCode(hatCityMapper.findByCityId(agentNewStatisticsVo.getCityCode()).getCity());
	        	agentNewStatisticsVo.setCountyCode(hatAreaMapper.findByAreaId(agentNewStatisticsVo.getCountyCode()).getArea());
	        }
	        
	        
	        PageInfo<AgentNewStatisticsVo> pageInfo = new PageInfo<>(agentIncomeList);
	        map1.put("code", Const.SUCCESS_CODE);
	        map1.put("message","查询成功");
	        map1.put("agentIncomeList",agentIncomeList);
	        map1.put("page",pageInfo);
		
		return map1;
	}

	@Override
	public int queryAgentIncomeListCount(Map<String, String> map) {
		
		return 0;
	}

}
